﻿var productPrice = ''; // 产品单价
$(function(){
	// 产品点击事件
	$('.block-list li label').click(function(){
		var proPrice = $(this).find('.pro_price').text();
		productPrice = proPrice;
		var num = $('#num').val();
		$('#price').val(num*productPrice);
	});
})

// 数量增加
function addnumber(){
	var num = $('#num').val();
	num = parseInt(num)+1;
	$('#num').val(num);
	if(null != productPrice && productPrice != ""){
		$('#price').val(num*productPrice)
	}
}

// 数量减少
function minnumber(){
	var num = $('#num').val();
	if(num > 1){
		num = parseInt(num)-1;
		$('#num').val(num);
		if(null != productPrice && productPrice != ""){
			$('#price').val(num*productPrice)
		}
	}
}

// 提交订单
function submitOrder(){
	var checkLabel = $('.block-list').find('input:radio[name="block-1"]:checked').next('label');
	var proName = $(checkLabel).find('.pro_name').text();
	if(null == proName || proName.trim().length <= 0){
		alert("请选择要购买的产品！");
		return;
	}
	var num = $('#num').val();
	var price = $('#price').val();
	if(null == price || price.trim().length <= 0){
		alert("产品价格不能为空！");
		return;
	}
	var name = $('#name').val();
	if(null == name || name.trim().length <= 0){
		alert("姓名不能为空！");
		return;
	}
	var mobile = $('#mobile').val();
	if(null == mobile || mobile.trim().length <= 0){
		alert("手机不能为空！");
		return;
	}
	var province = $('#s_province option:selected') .val();
	if(province == "选省份"){
		alert("请选择省份");
		return;
	}
	var city = $('#s_city option:selected') .val();
	if(city == "选城市"){
		alert("请选择城市");
		return;
	}
	var county = $('#s_county option:selected') .val();
	if(county == "选地区"){
		alert("请选择地区");
		return;
	}
	var area = province+city+county;
	var address = $('#address').val();
	if(null == address || address.trim().length <= 0){
		alert("地址不能为空！");
		return;
	}
	var remark = $('#remark').val();
	var payType = 0;
	$.post('http://test.51weiqiao.com:8090/chanyunge/frontOrders/addOrder',{
		"orders.pro_name":proName,"orders.num":num,"orders.price":price,"orders.name":name,"orders.source":$('#orderSource').val()
		,"orders.mobile":mobile,"orders.area":area,"orders.address":address,"orders.remark":remark,"orders.pay_type":payType},function(data){
		if(data.state == 1){
			alert("提交成功");
			window.location.reload();
		}else{
			alert("提交失败");
		}
		console.log(data);
	});
}